function [paths, distance] = ShortestPath(A,org)
%Uses Dijkstra's Algorithm to find the shortest path between the origin,o,
%and the target, t.

sizeA = max(size(A));

nodes = ones(1, sizeA);
distance = Inf*ones(1, sizeA);
previous = [org];
paths = cell(sizeA);
min = 0;
oldmin = Inf;
distance(org) = 0;

while(sum(nodes) > 0)
   oldmin = Inf;
   for i=1:sizeA
        if (nodes(i) == 1)
            min = distance(i);
            if (min < oldmin)
                oldmin = min;
            end    
        end
    end
        
    [r,c] = find(distance == oldmin);
    for i=1:max(size(c))
        if (nodes(c(i)) == 1)
            u = c(i);
            break;
        end
    end
            
    if (distance(u) == Inf)
        break;
    end
    
    nodes(u) = 0;
   
    for i=1:sizeA
        if (A(u,i) ~= 0 && nodes(i) ~= 0)
            paths(i(size(paths(i))) + 1) = i;
            if (distance(i) == Inf && A(org,i) == 0)
                distance(i) = 1 + distance(u);
            else
                if (distance(i) == Inf)
                    distance(i) = 1;
                end
            end
            if (distance(i) + A(u,i) < distance(i))
                distance(i) = distance(i) + A(u,i);
            end
        end
    end  
    %paths(u) = previous;
end
    
    







